package com.csweimei.rentmanagementtreasure.enterprise.act;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProviders;

import android.os.Bundle;

import com.chad.library.BR;
import com.csweimei.rentmanagementtreasure.R;
import com.csweimei.rentmanagementtreasure.base.AppViewModelFactory;
import com.csweimei.rentmanagementtreasure.databinding.ActivityCodeListBinding;
import com.csweimei.rentmanagementtreasure.enterprise.viewModel.CodeListVM;
import com.google.android.material.tabs.TabLayout;

import me.goldze.mvvmhabit.base.BaseActivity;

public class CodeListActivity extends BaseActivity<ActivityCodeListBinding, CodeListVM> {

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_code_list;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        super.initData();
        viewModel.setActivity(this);

        binding.tab.addTab(binding.tab.newTab().setText("全部"));
        binding.tab.addTab(binding.tab.newTab().setText("已失效"));
        binding.tab.getTabAt(0).select();

        binding.tab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                viewModel.state.set(""+tab.getPosition());
                viewModel.onResume();
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    @Override
    public CodeListVM initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this,factory).get(CodeListVM.class);
    }
}